import Vue from 'vue';
import Router from 'vue-router';
import Test from '@/components/page/Test';
import Home from '@/components/page/Home';
import LeaderDetail from '@/components/page/LeaderDetail';
import Leader from '@/components/page/Leader';
import DashBoard from '@/components/page/DashBoard';
import DataPackage from '@/components/page/DataPackage';
import DataSource from '@/components/page/DataSource';
import ChartLibrary from '@/components/page/ChartLibrary';
import ChartEditor from '@/components/page/ChartEditor';
import APIList from '@/components/page/APIList';
import API from '@/components/data/api.js';

import VueMaterial from 'vue-material';
import 'vue-material/dist/vue-material.min.css';
import '@/assets/iconfont/iconfont.css';

Vue.use(Router);
Vue.use(VueMaterial);
Vue.prototype.API=API;
Vue.prototype.app=new Vue();

//设置当前语言
var langType = window.localStorage.getItem('langType') ? window.localStorage.getItem('langType') : (window.navigator.language || window.navigator.browserLanguage).toLowerCase();
if (langType.indexOf('zh') >= 0) {
  langType = 'zh';
} else {
  langType = 'en';
}
if (!window.localStorage.getItem('langType')) {
  window.localStorage.setItem('langType', langType);
}

//获取语言类型 item为{zh:'',en:''}不同语言类型string的object
Vue.prototype.getLangText = function(item) {
  if (item) {
    if (this.langType == 'en') {
     
      if(item.en&&item.en.length>=2){
        var str=item.en ;
        return str.substring(0,1).toUpperCase()+str.substring(1,str.length);
      }else if(item.en){
        return str;
      }else{
        return '--'
      }
      
    } else {
      return item.zh ? item.zh : '--';
    }
  } else {
    return '--';
  }
};

//格式化日期时间
Date.prototype.format = function(fmt) {
  //author: meizz
  var o = {
    'M+': this.getMonth() + 1, //月份
    'd+': this.getDate(), //日
    'h+': this.getHours(), //小时
    'm+': this.getMinutes(), //分
    's+': this.getSeconds(), //秒
    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  for (var k in o) if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
  return fmt;
};

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      children: [{ path: 'leader', name: 'Leader', component: Leader },
      { path: 'dashboard', name: 'DashBoard', component: DashBoard },
      { path: 'datapackage', name: 'DataPackage', component: DataPackage },
      { path: 'datasource', name: 'DataSource', component: DataSource },
      { path: 'chartlibrary', name: 'ChartLibrary', component: ChartLibrary },
      { path: 'charteditor', name: 'ChartEditor', component: ChartEditor },
      { path: 'apilist', name: 'APIList', component: APIList },
    ],
    },
    
    {
      path: '/leader-detail',
      name: 'LeaderDetail',
      component: LeaderDetail,
    },
    {
      path:"/test",
      name:"Test",
      component:Test
    },
  ],
});
